package cn.jolyoulu.test.controller;

import cn.jolyoulu.test.entity.Test;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.jolyoulu.test.mapper.TestMapper;
import cn.jolyoulu.common.mybatis.plus.plugin.page.JlPage;
import cn.jolyoulu.common.web.entity.ResultInfo;

import java.util.UUID;

/**
 * @Author LuZhouJin
 * @Date 2023/5/4
 * mybatisplus-module 测试
 */
@RestController
@RequestMapping("/test/mybatis")
public class TestMybatisController {

    @Autowired
    private TestMapper testMapper;

    //测试新增
    @GetMapping("/insert")
    public ResultInfo<Boolean> mybatis() {
        String uuid = UUID.randomUUID().toString();
        Test test = new Test();
        test.setColumnOne(uuid);
        return ResultInfo.success(testMapper.insert(test) > 0);
    }

    //测试分页
    @GetMapping("/page")
    public ResultInfo<JlPage<Test>> mybatisPage(@RequestParam("page") Integer page,
                                                @RequestParam("pageSize") Integer pageSize) {
        return ResultInfo.success(JlPage.execute(page, pageSize, () -> testMapper.selectAll(),true));
    }

}
